﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO.Ports;
using System.Windows.Forms;

namespace Vosc
{
	// Token: 0x0200001C RID: 28
	public partial class FlashUpdateForm : Form
	{
		// Token: 0x17000015 RID: 21
		// (get) Token: 0x060000B2 RID: 178 RVA: 0x0000C18A File Offset: 0x0000A38A
		public string Port
		{
			get
			{
				return this.port;
			}
		}

		// Token: 0x17000016 RID: 22
		// (get) Token: 0x060000B3 RID: 179 RVA: 0x0000C192 File Offset: 0x0000A392
		public int Baudrate
		{
			get
			{
				return this.baudrate;
			}
		}

		// Token: 0x17000017 RID: 23
		// (get) Token: 0x060000B4 RID: 180 RVA: 0x0000C19A File Offset: 0x0000A39A
		public FlashUpdateType UpdateType
		{
			get
			{
				return this.updateType;
			}
		}

		// Token: 0x17000018 RID: 24
		// (get) Token: 0x060000B5 RID: 181 RVA: 0x0000C1A2 File Offset: 0x0000A3A2
		public bool IsUpdateKernal
		{
			get
			{
				return this.isUpdateKernal;
			}
		}

		// Token: 0x17000019 RID: 25
		// (get) Token: 0x060000B6 RID: 182 RVA: 0x0000C1AA File Offset: 0x0000A3AA
		public string FirmwareFile
		{
			get
			{
				return this.firmwareFile;
			}
		}

		// Token: 0x060000B7 RID: 183 RVA: 0x0000C1B2 File Offset: 0x0000A3B2
		public FlashUpdateForm()
		{
			this.InitializeComponent();
		}

		// Token: 0x060000B8 RID: 184 RVA: 0x0000C1C0 File Offset: 0x0000A3C0
		private void FlashUpdateForm_Load(object sender, EventArgs e)
		{
			string[] portNames = SerialPort.GetPortNames();
			this.comboBoxPort.Items.AddRange(portNames);
			if (this.comboBoxPort.Items.Count > 0)
			{
				this.comboBoxPort.SelectedIndex = 0;
			}
			this.comboBoxBaudrate.Items.Add("115200");
			this.comboBoxBaudrate.Items.Add("57600");
			this.comboBoxBaudrate.SelectedIndex = 0;
			this.comboBoxTarget.Items.AddRange(Enum.GetNames(typeof(FlashUpdateType)));
			this.comboBoxTarget.SelectedIndex = 0;
		}

		// Token: 0x060000B9 RID: 185 RVA: 0x0000C268 File Offset: 0x0000A468
		private void buttonUpdate_Click(object sender, EventArgs e)
		{
			if (this.comboBoxPort.SelectedItem == null)
			{
				MessageBox.Show("必须选择一个通信端口！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				return;
			}
			this.port = (string)this.comboBoxPort.SelectedItem;
			if (this.comboBoxBaudrate.Text == null || !int.TryParse(this.comboBoxBaudrate.Text, out this.baudrate))
			{
				MessageBox.Show("必须选择一个波特率！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				return;
			}
			this.updateType = (FlashUpdateType)Enum.Parse(typeof(FlashUpdateType), (string)this.comboBoxTarget.SelectedItem, true);
			if (string.IsNullOrEmpty(this.textBoxFile.Text))
			{
				MessageBox.Show("必须选择一个升级文件！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				return;
			}
			this.firmwareFile = this.textBoxFile.Text;
			this.isUpdateKernal = this.checkBox_Kernal.Checked;
			base.DialogResult = DialogResult.OK;
		}

		// Token: 0x060000BA RID: 186 RVA: 0x0000C35F File Offset: 0x0000A55F
		private void buttonCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		// Token: 0x060000BB RID: 187 RVA: 0x0000C368 File Offset: 0x0000A568
		private void buttonFile_Click(object sender, EventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.CheckFileExists = true;
			openFileDialog.CheckPathExists = true;
			openFileDialog.Multiselect = false;
			if (openFileDialog.ShowDialog(this) == DialogResult.OK)
			{
				this.textBoxFile.Text = openFileDialog.FileName;
			}
		}

		// Token: 0x060000BC RID: 188 RVA: 0x0000C3AC File Offset: 0x0000A5AC
		private void comboBoxTarget_SelectedIndexChanged(object sender, EventArgs e)
		{
			FlashUpdateType flashUpdateType = (FlashUpdateType)Enum.Parse(typeof(FlashUpdateType), (string)this.comboBoxTarget.SelectedItem, true);
			if (Enum.GetName(typeof(FlashUpdateType), flashUpdateType).Contains("DSP"))
			{
				this.checkBox_Kernal.Enabled = true;
				this.checkBox_Kernal.Checked = false;
				return;
			}
			this.checkBox_Kernal.Enabled = false;
			this.checkBox_Kernal.Checked = false;
		}

		// Token: 0x040000E0 RID: 224
		private string port;

		// Token: 0x040000E1 RID: 225
		private int baudrate;

		// Token: 0x040000E2 RID: 226
		private FlashUpdateType updateType;

		// Token: 0x040000E3 RID: 227
		private bool isUpdateKernal;

		// Token: 0x040000E4 RID: 228
		private string firmwareFile;
	}
}
